package cn.ichiva.game.gobang;

import java.awt.*;
import java.util.LinkedList;
import java.util.Random;

/**
 * @Description
 * @auther Chiva 874460517@qq.com
 * @create 2020-01-08 14:40
 */
public class Main {

    public static void main(String[] args) {
        LinkedList<Point> linkedList = new LinkedList<>();
        for (int x = 0; x < Gobang.xLen; x++) {
            for (int y = 0; y < Gobang.yLen; y++) {
                linkedList.add(new Point(x,y));
            }
        }

        int sum = 0;
        while(true){
            sum++;
            Gobang gobang = new Gobang();
            Random random = new Random();

            LinkedList<Point> clone = (LinkedList<Point>) linkedList.clone();


            for (int i = 0; i < 100; i++) {
                int index = random.nextInt(clone.size());
                Point remove = clone.remove(index);
                System.out.println("落子点:"+remove);

                boolean flag = gobang.getFlag();
                boolean play = gobang.play(remove.x, remove.y, flag);
                if(play){
                    System.out.println("winner is " + flag);
                    System.out.println("总局数: "+sum);
                    return;
                }

                System.out.println(gobang);
            }
        }


    }

}
